package com.yin.sdktest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.pactera.pjsip_sdk.PjSip;
import com.pactera.pjsip_sdk.listeners.OnSipListener;

import net.gotev.sipservice.CallInAccountData;
import net.gotev.sipservice.CallOutAccountData;
import net.gotev.sipservice.SipAccountData;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PjSip.getInstance().init(this);
        PjSip.getInstance().setOnSipListener(new OnSipListener() {
            @Override
            public void onOutGoing(String account) {

            }

            @Override
            public void onInGoing(String account) {
                CallInAccountData callInAccountData = new CallInAccountData();
                callInAccountData.setAccount(account);
                callInAccountData.setName("测试名称");
                callInAccountData.setUrl("头像URL");
                PjSip.getInstance().setCallInAccountData(callInAccountData);
            }

            @Override
            public void onSpeak(boolean b) {

            }

            @Override
            public void onMute(boolean b) {

            }

            @Override
            public void onHangUp() {

            }

            @Override
            public void onAccept() {

            }

            @Override
            public void onMini() {

            }
        });

        findViewById(R.id.btn_call).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CallOutAccountData callOutAccountData = new CallOutAccountData();
                callOutAccountData.setAccount("1002");
                callOutAccountData.setName("对方名称");
                callOutAccountData.setUrl("头像url");
                PjSip.getInstance().makeCall(callOutAccountData);
            }
        });

        findViewById(R.id.btn_regist).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SipAccountData sipAccountData = new SipAccountData();
                sipAccountData.setPort(5060);
                sipAccountData.setPassword("1234");
                sipAccountData.setUsername("1003");
                sipAccountData.setRealm("192.168.2.102");
                sipAccountData.setHost("192.168.2.102");
                PjSip.getInstance().regist(sipAccountData);
            }
        });

        findViewById(R.id.btn_un_regist).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PjSip.getInstance().unRegist();
                PjSip.getInstance().setPrefix("1");
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        PjSip.getInstance().destroy();
    }
}
